﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fitment.Budget
{
    public partial class ResultInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            double floorarea = 0;
            double wallarea = 0;
            double doorarea = 0;
            double windowarea = 0;


            string strConnection = ConfigurationManager.ConnectionStrings["connection"].ToString();//读取配置文件连接信息
            string queryRoom = "SELECT * FROM RoomInfo;";
            string queryWindow = "SELECT * FROM WindowInfo;";
            string queryDoor = "SELECT * FROM DoorInfo;";
            string kk = "INSERT INTO HouseInfo (DoorCount, WindCount,RoomCount) VALUES (21, 21,21);";

            using (SqlConnection connection = new SqlConnection(strConnection))
            {
                SqlCommand command = new SqlCommand(kk, connection);
                command.Connection.Open();
                command.ExecuteNonQuery();
            }

            using (SqlConnection RoomConnection = new SqlConnection(strConnection)) 
            {
                SqlCommand RoomCommand = new SqlCommand(queryRoom, RoomConnection);
                RoomConnection.Open();
                SqlDataReader RoomReader = RoomCommand.ExecuteReader();
                // Call Read before accessing data.
                while (RoomReader.Read())
                {
                    floorarea += Convert.ToInt32(RoomReader[4]) * Convert.ToInt32(RoomReader[5]);
                    wallarea += (Convert.ToInt32(RoomReader[3]) * Convert.ToInt32(RoomReader[4]) + Convert.ToInt32(RoomReader[3]) * Convert.ToInt32(RoomReader[5])) * 2;
                }
                // Call Close when done reading.
                RoomReader.Close();
                RoomConnection.Close();
            }
            
            using (SqlConnection WindowConnection = new SqlConnection(strConnection))
            {
                SqlCommand WindowCommand = new SqlCommand(queryWindow, WindowConnection);
                WindowConnection.Open();
                SqlDataReader WindowReader = WindowCommand.ExecuteReader();
                while (WindowReader.Read())
                {
                    windowarea += Convert.ToInt32(WindowReader[3]) * Convert.ToInt32(WindowReader[4]);
                }
                WindowReader.Close();
                WindowConnection.Close();
            }

            using (SqlConnection DoorConnection = new SqlConnection(strConnection))
            {
                SqlCommand DoorCommand = new SqlCommand(queryDoor, DoorConnection);
                DoorConnection.Open();
                SqlDataReader DoorReader = DoorCommand.ExecuteReader();
                while (DoorReader.Read())
                {
                    doorarea += Convert.ToInt32(DoorReader[3]) * Convert.ToInt32(DoorReader[4]);
                }
                DoorReader.Close();
                DoorConnection.Close();
            }

            Label9.Text = (floorarea / 10000).ToString() + "平";
            Label10.Text = (floorarea / 10000).ToString() + "平";
            Label16.Text = ((floorarea * 8) / 10000).ToString() + "元";
            Label14.Text = ((floorarea * 100) / 10000).ToString() + "元";
            Label11.Text = ((wallarea + floorarea) / 10000).ToString() + "平";
            Label18.Text = (((wallarea + floorarea) * 12) / 10000).ToString() + "元";
            Label12.Text = (floorarea / 10000).ToString() + "平";
            Label20.Text = ((floorarea * 25) / 10000).ToString() + "元";
            Label23.Text = (windowarea/10000).ToString() + "平";
            Label25.Text = (doorarea / 10000).ToString() + "平";
        }
    }
}
